//
//  AppController.m
//  CocOCaml
//
//	$Id: AppController.m,v 1.1.1.1 2003/02/27 16:53:39 wneuman Exp $
//
//  Created by William D. Neumann on Sun Feb 16 2003.
//  Copyright (c) 2003 William D. Neumann. All rights reserved.
//
//	This program is free software; you can redistribute it and/or modify
//	it under the terms of the Artistic License as published by Larry
//	Wall, either version 2.0, or (at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	Artistic License for more details.
//
//	You should have received a copy of the Artistic License with this Kit,
//	in the file named "Artistic.clarified".  If not, I'll be glad to provide
//	one.
//

#import "AppController.h"
#import "PreferenceController.h"

@implementation AppController

+ (void) initialize
{
    NSMutableDictionary* defaults = [NSMutableDictionary dictionary];

    [defaults setObject:@"/usr/local/bin/ocaml" forKey:WDNInterpreterPathKey];
    [defaults setObject:@"" forKey:WDNInterpreterArgsKey];
    [defaults setObject:@"NO" forKey:WDNInitialPrefsSetKey];
    [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
}

- (id) init
{
    self = [super init];
    if (self) {
        //	Ensure that interpreter path & args were initially set
        if (![[NSUserDefaults standardUserDefaults] boolForKey:WDNInitialPrefsSetKey]) {
            //	If not, load the preferences Nib
            if (!preferenceController) {
                preferenceController = [[PreferenceController alloc] init];
            }
            [preferenceController showWindow:self];
        }
    }
    return self;
}

- (IBAction) showPreferencePanel:(id)sender
{
    if (!preferenceController) {
        preferenceController = [[PreferenceController alloc] init];
    }
    [preferenceController showWindow:self];
}

- (IBAction) showAboutPanel:(id)sender
{
    if (aboutPanel == nil) {
        if (![NSBundle loadNibNamed:@"AboutPanel.nib" owner:self]) {
            NSLog(@"Load of AboutPanel.nib failed");
            return;
        }
    }
    [aboutPanel makeKeyAndOrderFront:nil];
}

- (void) dealloc
{
    [preferenceController release];
    [super dealloc];
}

@end
